//
// author xiongyongshun
// project go_redis
// version 1.0
// created 16/10/6 03:49
//
package main

import (
	"fmt"
	"gopkg.in/redis.v4"
	"time"
)

func main() {
	client := createClient()
	defer client.Close()
	setOperation(client)
}

// 创建 redis 客户端
func createClient() *redis.Client {
	client := redis.NewClient(&redis.Options{
		Addr:     "127.0.0.1:6379",
		Password: "",
		DB:       0,
		PoolSize: 5,
	})

	pong, err := client.Ping().Result()
	fmt.Println(pong, err)

	return client
}

func getVaule(n int) string {
	val := make([]byte,0, n)
	for i := 0; i <= n; i++ {
		val = append(val, 'a')
	}
	return string(val)
}

// set 操作
func setOperation(client *redis.Client) {
	tag := 5000
	value := getVaule(tag)
	for i := 0; i <= 100000; i ++ {
		key := fmt.Sprintf("%v_%v_%v", "redis", tag, i)
		client.Set(key, value, time.Second*60*60)
	}
	//data := client.Get(fmt.Sprintf("%v_%v_%v", "redis", tag, value))
	//fmt.Println(data)
}